﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LunwenYun.Infrastructure.Entities.Repository;
using LunwenYun.Infrastructure.Entities.Enum;

namespace LunwenYun.Infrastructure.Entities.Entity
{
    public class Article : IAccessible<T_Article, Article>, ILogicEntity<T_Article, Article>
    {
        #region
        public int Id { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// Aptitude
        /// </summary>
        public string Aptitude { get; set; }
        /// <summary>
        /// Language
        /// </summary>
        public Language Language { get; set; }
        /// <summary>
        /// 行业分类
        /// </summary>
        public IndType IndType { get; set; }
        public SubIndType SubIndType { get; set; }
        /// <summary>
        /// 稿件标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 稿件标题_EN
        /// </summary>
        public string Title_EN { get; set; }
        /// <summary>
        /// 摘要
        /// </summary>
        public string Abstract { get; set; }
        /// <summary>
        /// 摘要_EN
        /// </summary>
        public string Abstract_EN { get; set; }
        /// <summary>
        /// 关键词
        /// </summary>
        public string KeyWords { get; set; }
        /// <summary>
        /// 关键词_EN
        /// </summary>
        public string KeyWords_EN { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime ExpireTime { get; set; }
        public int PageSize { get; set; }
        /// <summary>
        /// 联系方式
        /// </summary>
        public string ContactInfo { get; set; }
        public string QQ { get; set; }
        /// <summary>
        /// 费用范围
        /// </summary>
        public string PriceRange { get; set; }
        public ArticleStatus Status { get; set; }
        public bool AcceptShortMessage { get; set; }
        public bool IsDelete { get; set; }
        #endregion

        public List<MessageBoard> MessageBoard { get; set; }
        public Periodical Periodical { get; set; }

        protected override void Covariant(T_Article model)
        {
            if (model != null)
            {
                this.Abstract = model.Abstract;
                this.Abstract_EN = model.Abstract_EN;
                this.AcceptShortMessage = model.AcceptShortMessage;
                this.CreateTime = model.CreateTime;
                this.ExpireTime = model.ExpireTime;
                this.Id = model.Id;
                this.IndType = (IndType)model.IndType;
                this.IsDelete = model.IsDelete;
                this.KeyWords = model.KeyWords;
                this.KeyWords_EN = model.KeyWords_EN;
                this.PageSize = model.PageSize;
                this.PriceRange = model.PriceRange;
                this.Title = model.Title;
                this.Title_EN = model.Title_EN;
                this.UserName = model.UserName;
                this.ContactInfo = model.ContactInfo;
                this.QQ = model.QQ;
                this.Aptitude = model.Aptitude;
                this.Status = (ArticleStatus)model.Status;
                this.Language = (Language)model.Language;
                this.SubIndType = (SubIndType)model.SubIndType;
            }
        }

        protected override T_Article Inverter(Article model)
        {
            if (model != null)
            {
                return new T_Article()
                {
                    Abstract = model.Abstract,
                    Abstract_EN = model.Abstract_EN,
                    AcceptShortMessage = model.AcceptShortMessage,
                    CreateTime = model.CreateTime,
                    ExpireTime = model.ExpireTime,
                    Id = model.Id,
                    IndType = (int)model.IndType,
                    Aptitude=model.Aptitude,
                    Language=(int)model.Language,
                    SubIndType=(int)model.SubIndType,
                    IsDelete = model.IsDelete,
                    KeyWords = model.KeyWords,
                    KeyWords_EN = model.KeyWords_EN,
                    PageSize = model.PageSize,
                    PriceRange = model.PriceRange,
                    Title = model.Title,
                    Title_EN = model.Title_EN,
                    UserName = model.UserName,
                    ContactInfo=model.ContactInfo,
                    QQ=model.QQ,
                    Status = (int)model.Status
                };
            }
            return null;
        }

        public Article Set(T_Article dbModel)
        {
            Covariant(dbModel);
            return this;
        }

        public Article LoadMessages(List<MessageBoard> messageBoard)
        {
            this.MessageBoard = messageBoard.Where(c => c != null).ToList();
            return this;
        }

        public Article LoadPeriodical(T_Periodical t_Periodical)
        {
            this.Periodical = new Periodical().Set(t_Periodical);
            return this;
        }
    }
}
